home *** CD-ROM | disk | FTP | other *** search
/ Maclife 157 / MACLIFE157-2001-09.ISO.7z / MACLIFE157-2001-09.ISO / Linux / MacOS Tools / BootX 1.2.2 / Sources / src / common / boot.h < prev    next >
Text File  |  2001-07-23  |  6KB  |  156 lines

  1. /* BootX
  2.  *
  3.  * Written by Benjamin Herrenschmidt
  4.  *
  5.  * portions of this code from InfiniteOS boot loader by <...>, portions from
  6.  * quik by Paul Mackerras.
  7.  *
  8.  * GPL....
  9.  *
  10.  * This file contains all the code involved in loading kernels, ramdisks,
  11.  * preparing the boot environement and doing the actual boot.
  12.  * It's shared between BootX and miBoot
  13.  *
  14.  * NOTES: - The enclosing module must export a "dct" variable containing the
  15.  *          dt_context used for debugging.
  16.  *        - This modules uses the NameRegistry API when running on a PCI machine.
  17.  *          If compiling 68k code, you need to provide the NR API via the wrappers
  18.  *          in the same link unit.
  19.  *        - We do pass FSSpecs, but we never use FSpXXXX functions in case they are
  20.  *          not in ROM.
  21.  *        - This version still uses Gestalt which can cause trouble with older ROMs.
  22.  *            We should check before using. Will NuBus PPC ROMs support it ? This may
  23.  *          be an issue for 68k only (but most of this code should work with 68k macs)
  24.  *
  25.  *
  26.  * This module requires BOOTX_ENV to be defined to one of those:
  27.  *    BOOTX_ENV_APPLICATION        Application version, uses files and system heap
  28.  *    BOOTX_ENV_EXTENSION        Extension version, uses files and bufptr memory
  29.  *    BOOTX_ENV_RAW                Boot block version, uses block/io and bufptr memory
  30.  *
  31.  * Both file desc structure use either a FSSpec/fileRefNum (application and extension)
  32.  * or a block map with a driver refNum (boot blocks). There's currently no way to use
  33.  * "raw" SCSK or ATA without a driver. In the boot block version, open and close are
  34.  * skipped and the block map is expected to be provided by the caller.
  35.  * The block map format is a semi-compressed map formed of pairs of long words:
  36.  * [block_number][block_count] [block_number][block_count] ...
  37.  * The end of the map is marked by a (0,0) entry.
  38.  *
  39.  * The bootblock version must be linked with a couple more globals:
  40.  *   Ptr    g_low_68k_strap            pointer to low-level 68k bootstrap entry
  41.  *     Ptr    g_low_PPC_pre_strap        pointer to low-level PPC bootstrap entry
  42.  *   Ptr    g_low_PPC_strap            pointer to low-level PPC boostrap
  43.  *
  44.  */
  45.  
  46. #ifndef __BOOTX_BOOT_H__
  47. #define __BOOTX_BOOT_H__
  48.  
  49. #include "bootx.h"
  50.  
  51. #ifndef BOOTX_ENV
  52. #error BOOTX_ENV not defined !
  53. #endif
  54.  
  55. #define    BOOTX_ENV_APPLICATION    0
  56. #define    BOOTX_ENV_EXTENSION        1
  57. #define    BOOTX_ENV_RAW            2
  58.  
  59. //#define BOOTX_USES_FILES        (BOOTX_ENV != BOOTX_ENV_RAW)
  60. #define BOOTX_USES_FILES        1
  61. #define BOOTX_USES_BUFPTR        (BOOTX_ENV != BOOTX_ENV_APPLICATION)
  62.  
  63. /* This option reverts to old bootx behaviour:
  64.    the kernel is entered directly, without turnig OFF the MMU. */
  65. #ifndef NO_BOOTSTRAP
  66. #define NO_BOOTSTRAP            0
  67. #endif
  68.  
  69. //#if BOOTX_ENV == BOOTX_ENV_RAW
  70. //extern Ptr    g_low_68k_strap;        // pointer to low-level 68k bootstrap entry
  71. //extern Ptr    g_low_PPC_pre_strap;    // pointer to low-level PPC bootstrap entry
  72. //extern Ptr    g_low_PPC_strap;        // pointer to low-level PPC boostrap
  73. //#endif
  74.  
  75. /* This is a pseudo-file struture */
  76. typedef struct boot_file {
  77. #if BOOTX_USES_FILES
  78.     FSSpec        spec;    /* MacOS FSSpec */
  79. #else
  80.     UInt32*        map;    /* Block map (number-count) */
  81. #endif    
  82.     short        rn;        /* MacOS refNum or -1 */    
  83.     UInt32        size;    /* File size */
  84.     StringPtr    name;    /* Pointer to name */
  85.     
  86. } boot_file_t;
  87.  
  88. /* This structure describes a kernel file, with all informations
  89.    required by the boot code about it.
  90.  */
  91. typedef struct boot_kernel_desc {
  92.     boot_file_t*    file;
  93.     UInt32            offset;        /* Offset of kernel image in file */
  94.     UInt32            size;        /* Size of kernel image in file */
  95.     UInt32            mem_size;    /* Memory footprint of the kernel */
  96.     UInt32            entry;        /* Relative entry point  */
  97.     UInt32            load_base;    /* Kernel expected load base */
  98.     Boolean            zImage;        /* File is gzipped XCOFF */
  99. } boot_kernel_desc_t;
  100.  
  101. /* This structure describes a ramdisk file. This can be the same file
  102.    as the kernel file.
  103.  */
  104. typedef struct boot_ramdisk_desc {
  105.     boot_file_t*    file;
  106.     UInt32            offset;        /* Offset of the ramdisk image in the file */
  107.     UInt32            size;        /* Size of the ramdisk image in the file */
  108. } boot_ramdisk_desc_t;
  109.  
  110. /* This structure contains various parameters passed to do_boot */
  111. typedef struct boot_params {
  112.     char*            args;            /* Kernel args (command line) */
  113.     Boolean            setup_video;
  114.     Boolean            force_scsi;
  115.     Boolean            close_video;
  116.     Boolean            override_l2cr;
  117.     UInt32            l2cr_value;
  118.     Boolean            no_relocation;
  119.     Boolean            reset_ata;
  120. } boot_params_t;
  121.  
  122. /* Checks a file supposed to be a kernel. This function will open the file,
  123.    try to guess it's format, fill out the passed in structures according to
  124.    the file content and return wether this file was a valid kernel or not.
  125.    Note that only some fields are filled in the scructure. do_boot() will
  126.    take care of the remaining fields.
  127.  */
  128. Boolean    check_kernel_file(    boot_file_t         *in_file,
  129.                             boot_kernel_desc_t    *out_kernel_infos,
  130.                             boot_ramdisk_desc_t    *out_ramdisk_infos,
  131.                             Boolean                *out_has_ramdisk);
  132.  
  133. /* Checks a ramdisk file. The current implementation returns true all
  134.    the time if the file exists and fills out the boot_ramdisk_desc_t with
  135.    infos about the entire file data fork without opening it.
  136.  */
  137. Boolean check_ramdisk_file(    boot_file_t            *in_file,
  138.                             boot_ramdisk_desc_t    *out_ramdisk_infos);
  139.                             
  140. /* This function does the actual boot of the kernel, prepares all data
  141.    structurees and boot. Note that only the application version will return
  142.    from this function when successfull. In this case, the application is
  143.    expected to quit as soon as possible. Files will have been closed.
  144.  */
  145. enum boot_kind {
  146.     boot_miBoot,
  147.     boot_extension,
  148.     boot_application
  149. };
  150.  
  151. OSStatus do_boot(            boot_kernel_desc_t    *in_kernel_infos,
  152.                             boot_ramdisk_desc_t    *in_ramdisk_infos,
  153.                             boot_params_t        *in_params);
  154.  
  155.  
  156. #endif